import java.util.Deque;
import java.util.LinkedList;

public class QTest {
      public static void main(String[] args) {
//            QTest.getQue();
//            QTest.getLinkedLIst();
            QTest.test();
      }
      public static void getQue(){

            Deque de=new LinkedList();
            Student stu1 = new Student("高晨曦", "软件专业", 3, "nice", 20);
            Student stu2 = new Student("张思韬", "软件专业", 3, "nice", 21);
            Student stu3 = new Student("姜万里", "计算机专业", 1, "nice", 22);
            Student stu4 = new Student("郭佳宝", "计算机专业", 1, "nice", 21);
            Student stu5 = new Student("方周", "计算机专业", 1, "nice", 24);

            Object obj;

            //这个展示从offerLast()和offerFrist()的区别：
            /*
               offerLast()表示从从链表的尾部开始，1,2,3->这样插入元素 [1,2,3] =>[1,2,3,4] =>[1,2,3,4,5]这样添加元素
               offerFrist()表示从链表的头开始，<-3,2,1这样插入元素 [1,2,3] => [4,1,2,3] => [5,4,1,2,3]这样添加元素
          */
            de.offerLast(stu1);
            de.offerLast(stu2);
            de.offerLast(stu3);
            de.offerFirst(stu4);
            de.offerFirst(stu5);

            //这个展示从polllLast()和pollFrist()的区别：
            /*
                  pollLast()从后面往前删元素 [1,2,3,4] =>[1,2,3] =>[1,2]
                  pollFirst()从前往后删元素  [1,2,3,4].pollFirst() => [2,3,4] =>[3,4]
          */
            System.out.println("---------------------");
            for (int i = 0; i < 3; i++) {
                  Object ofir = de.pollFirst();
                  //检索并删除此列表的第一个元素，如果此列表为空，则返回null。
                  System.out.println(ofir);//打印删除的元素
            }

            System.out.println("---------------------");
            for (int i = 0; i < 3; i++) {
                  Object olas = de.pollLast();
                  //检索并删除此列表的最后一个元素，如果此列表为空，则返回null。
                  System.out.println(olas);//打印删除的元素
            }

            System.out.println("---------------------");
            System.out.println(de);

            System.out.println("=========================");

      }

      public static void getLinkedLIst(){
            // 声明一个LinkedList
            LinkedList list = new LinkedList();

            // 添加元素
            list.add("Geeks");
            list.add(4);
            list.add("Geeks");
            list.add(8);

            // 打印列表
            System.out.println("The initial Linked list is : " + list);

            // 插入新元素
            // 在尾部添加元素。
            list.offer("Astha");

            // 打印新列表
            System.out.println("LinkedList after insertion using offer() : " + list);
      }

      public static void test(){
            /*
               将三个元素从前插入，两个元素从后面插入
               从前遍历前两个元素，从后遍历后3个元素
          */
            LinkedList list=new LinkedList();
            list.offerFirst(1);
            list.offerFirst(2);
            list.offerFirst(3);

            list.offerLast(8);
            list.offerLast(10);
            //[3,2,1,8,10]：这样的顺序

            //从前遍历两个元素
            for(int i=0;i<2;i++){
                  Object obj= list.pollFirst();
                  System.out.print(obj+"  ");//[3,2]
            }

            System.out.println();
            System.out.println("=============");
            System.out.println(list);
            System.out.println("=============");

            //从后面往前遍历后3个元素
            for(int j=0;j<3;j++){
                  Object o=list.pollLast();//[10,8,1]
                  System.out.print(o+"  ");
            }
            list.pollFirst();
      }
}
class Student{
      //姓名
      public String name;
      //专业
      public String major;
      //班级
      public int sclass;
      //评论
      public String desc;
      //年龄
      public int age;

      public Student() {

      }

      public Student(String name, String major, int sclass) {
            this.name = name;
            this.major = major;
            this.sclass = sclass;
      }

      public Student(String name, String major, int sclass, String desc, int age) {
            this.name = name;
            this.major = major;
            this.sclass = sclass;
            this.desc = desc;
            this.age = age;
      }

      public String getName() {
            return name;
      }

      public void setName(String name) {
            this.name = name;
      }

      public String getMajor() {
            return major;
      }

      public void setMajor(String major) {
            this.major = major;
      }

      public int getSclass() {
            return sclass;
      }

      public void setSclass(int sclass) {
            this.sclass = sclass;
      }

      public String getDesc() {
            return desc;
      }

      public void setDesc(String desc) {
            this.desc = desc;
      }

      public int getAge() {
            return age;
      }

      public void setAge(int age) {
            this.age = age;
      }

      @Override
      public String toString() {
            return "Student{" + "name=" + name + "  age=" + age + "}"+"\n";
      }

}

